Java 11 Quick Start by Mala Gupta
Author:Mala Gupta [Mala Gupta]
Language: eng
Format: epub
Publisher: Packt Publishing
Published: 2018-10-08T21:00:00+00:00
Summary
In this chapter, you covered local variable inference, or var, introduced in Java 10. The var type enables you to drop the explicit data type for a local variable in a method. You covered the various do's and don'ts for the usage of var. Limited to local variables, variables defined using var must be initialized with a non-null value. They can be used with all type of variables—primitives and objects. Variables defined with var can also be passed to methods and returned from methods, method declaration compatibility rules apply.
To avoid risking your type safety with generics, ensure you pass relevant information, while using var with generics. Though it doesn't make a lot of sense, using explicit casting is allowed with variables defined using var. You also covered type inference existed in previous versions of Java, namely, 5, 7, and 8. Towards the end, you also covered why type inference is limited to the local variables and not allowed in the public API.
Usage of meaning variable names has always been recommended and it is important. With var, it becomes more important. Since var offers syntactic sugar, it doesn't make any sense to refactor your existing or legacy code to use var in it.
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Deep Learning with Python by François Chollet(12575)
Hello! Python by Anthony Briggs(9916)
OCA Java SE 8 Programmer I Certification Guide by Mala Gupta(9796)
The Mikado Method by Ola Ellnestam Daniel Brolund(9779)
Dependency Injection in .NET by Mark Seemann(9340)
Algorithms of the Intelligent Web by Haralambos Marmanis;Dmitry Babenko(8301)
Test-Driven iOS Development with Swift 4 by Dominik Hauser(7763)
Grails in Action by Glen Smith Peter Ledbrook(7697)
The Well-Grounded Java Developer by Benjamin J. Evans Martijn Verburg(7557)
Becoming a Dynamics 365 Finance and Supply Chain Solution Architect by Brent Dawson(7089)
Microservices with Go by Alexander Shuiskov(6858)
Practical Design Patterns for Java Developers by Miroslav Wengner(6777)
Test Automation Engineering Handbook by Manikandan Sambamurthy(6714)
Secrets of the JavaScript Ninja by John Resig Bear Bibeault(6419)
Angular Projects - Third Edition by Aristeidis Bampakos(6125)
The Art of Crafting User Stories by The Art of Crafting User Stories(5650)
NetSuite for Consultants - Second Edition by Peter Ries(5583)
Demystifying Cryptography with OpenSSL 3.0 by Alexei Khlebnikov(5392)
Kotlin in Action by Dmitry Jemerov(5066)
